<?php
	function CargaBrowserUserAgent(){
		srand ((double)microtime()*10000000);
        $browserAgentListFile = file (str_replace('\\','/',dirname(__FILE__)).'/usragts.txt');
        $line = $browserAgentListFile[array_rand ($browserAgentListFile)];
		$line = trim($line);
		$line = str_replace("\t", "", $line);
		$line = str_replace("\n", "", $line);
        return $line;
	}
	
	/*::::Curl::::*/
	function ejecutaCurlddd($URL) 
	{
		$userAgent = CargaBrowserUserAgent();
		$BOT_BROWSER_COOKIES = dirname(__FILE__).'/BotCookie.txt';
		//header("Content-Type: text/html; charset=utf-8");
		$curl = curl_init(); // Iniciando Curl
		curl_setopt($curl, CURLOPT_URL, $URL);
		curl_setopt($curl, CURLOPT_HEADER, 0);
		//curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3');
		curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
		curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($curl, CURLOPT_REFERER, 'http://www.amen-amen.net/');
		curl_setopt($curl, CURLOPT_COOKIEFILE, $BOT_BROWSER_COOKIES); //archivo para guardar las cookies generadas 
		curl_setopt($curl, CURLOPT_COOKIEJAR, $BOT_BROWSER_COOKIES); //archivo para guardar las cookies generadas 
		$htmlResultPage = curl_exec($URL);
		curl_close($curl);
		return $htmlResultPage;
	}

	function ejecutaCurl($URLDETALLE) 
	{
		$userAgent = CargaBrowserUserAgent();
		$BOT_BROWSER_COOKIES = dirname(__FILE__).'/BotCookie.txt';
		//header("Content-Type: text/html; charset=utf-8");
		$curldetalle = curl_init();
		curl_setopt($curldetalle, CURLOPT_URL, $URLDETALLE); 
		curl_setopt($curldetalle, CURLOPT_HEADER, 0);
		//curl_setopt($curldetalle, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3');
		curl_setopt($curldetalle, CURLOPT_USERAGENT, $userAgent);
		curl_setopt($curldetalle, CURLOPT_RETURNTRANSFER, true); 
		curl_setopt($curldetalle, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($curldetalle, CURLOPT_REFERER, 'http://www.amen-amen.net/');
		curl_setopt($curldetalle, CURLOPT_COOKIEFILE, $BOT_BROWSER_COOKIES); //archivo para guardar las cookies generadas 
		curl_setopt($curldetalle, CURLOPT_COOKIEJAR, $BOT_BROWSER_COOKIES); //archivo para guardar las cookies generadas 
		$htmlResultPageDetalle = curl_exec($curldetalle);
		curl_close($curldetalle);
		return $htmlResultPageDetalle;
	}
	/*::::Fin Curl::::*/

	/*::::Lectura de Patrones::::*/
	function lecturaPatronAll($patron,$htmlResultPage) 
	{	
		preg_match_all($patron, $htmlResultPage, $resultado);	
		return $resultado;
	}
	function lecturaPatron($patron,$htmlResultPage) 
	{	
		preg_match($patron, $htmlResultPage, $resultado);	
		return $resultado;
	}
	function remplacePatron($patron, $elementRemplace, $cadena) 
	{	
		$resultado = preg_replace($patron, $elementRemplace, $cadena);
		return $resultado;
	}
	/*::::Fin Lectura de patrones::::*/	
?>